import sys
import asyncio
import time
from collections import defaultdict

VERSION = ''
with open('/inc/version.inc') as f:
    lines = f.readlines()
    VERSION = lines[0].split('=')[1].strip()
sys.path.append('/opt/version/' + VERSION)
sys.path.append('/opt/version/' + VERSION + '/python-libs')
from data_struct import *

from nano_object import (
    InstrumentInfo,
    OrderTrade,
    Balance,
    Position,
)

from databox.pydatabox import DataBox
from securitymanager.pysecuritymanager import SecurityManager as Smc
from log import *
import traceback
from command_helper import TradeClient
import multiprocessing as mp
from nanomsg_util import NanomsgSuber

hft_setting = {
    "redis_host": "localhost",
    "redis_port": 8379,
    "redis_password": "refZa2KcTj$QjyXk",
    "oms_tcmd": "tcp://127.0.0.1:5555",
    "oms_rcmd": "tcp://127.0.0.1:7777",
    "inst_type": "USDT_SWAP",
    "subscribe_codes": [
        # "BTSE.SPOT.ETH-USDT.DEPTH1",
        # "BTSE.SPOT.BTSE-USDT.DEPTH20",
        # "BTSE.SPOT.BTSE-USDT.TRADES",
        "BTSE.SPOT.BTSE-USDT.DEPTH1"
        # "UNISWAP.SPOT.BTSE-ETH.DEPTH1"

    ],
    "balance_cod"
    "es": ["BTSE", "USDT"],
    "timer_interval": 1000,
    "strategyId": "yn_ts03",
    "account_path": "/home/yinan.chen/bzbn/mt/bzbn_account.csv"
}

smc = Smc(hft_setting["redis_host"], hft_setting["redis_port"], hft_setting["redis_password"], True)
databox = DataBox(hft_setting["redis_host"], hft_setting["redis_port"], hft_setting["redis_password"])
# 检查合约
exchange = "BTSE"
inst_type_str = "SPOT"
instrument = "BTSE-USDT"

# ok, smc_info = smc.get_instrument_info(exchange, inst_type_str, instrument)
# print(ok)
# print(smc_info)


# 检查get
ok, key, data = databox.get_md(exchange, inst_type_str, "DEPTH20", instrument)
print(ok)
print(key)
print(data)